﻿using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using PlanB.ShareDove.ConferenceOrganization.Portal.WebParts.MVP;

namespace PlanB.ShareDove.ConferenceOrganization.Portal.WebParts.DisplaySessions
{
    /// <summary>
    /// DisplaySessions Web Part - displays the conference sessions based on the selected criteria
    /// </summary>
    [ToolboxItemAttribute(false)]
    public class DisplaySessions : WebPart
    {
        /// <summary>
        /// Visual Studio might automatically update this path when you change the Visual Web Part project item.
        /// </summary>
        private const string _ascxPath = @"~/_CONTROLTEMPLATES/PlanB.ShareDove.ConferenceOrganization.Portal.WebParts/DisplaySessions/DisplaySessionsUserControl.ascx";

        /// <summary>
        /// Presenter instance (for MVP pattern)
        /// </summary>
        private DisplaySessionsPresenter presenter;

        /// <summary>
        /// CreateChildControls method of the DisplaySessions web part
        /// </summary>
        protected override void CreateChildControls()
        {
            DisplaySessionsUserControl control = Page.LoadControl(_ascxPath) as DisplaySessionsUserControl;
            Controls.Add(control);

            //instantiate presenter
            presenter = new DisplaySessionsPresenter(control);

            // In this variation of the MVP pattern, the Webpart can talk directly to the presenter. 
            presenter.RetreiveSessionData();
        }
    }
}
